module WhoCharted
  module ChartFeatures
    module AxisLabels
      module ClassMethods
        def accepted_arguments
          super + [:axis_labels]
        end

        def argument_dictionary
          super.merge(:axis_labels =>
                      {:key => 'chxl', :method => :gather_axis_labels})
        end
      end

      def self.included base
        base.extend ClassMethods
      end

      def gather_axis_labels
        axis_labels[0].class == Array ? \
          axis_labels.map {|l| "#{l[0]}:|#{l[1..l.length - 1].join('|')}"}.join('|') : \
          "#{axis_labels[0]}:|#{axis_labels[1..axis_labels.length - 1].join('|')}"
      end

      attr_reader :axis_labels

      private
      
      attr_writer :axis_labels
    end
  end
end
